# -*- coding: utf-8 -*-
"""
@Time ： 2023/4/23 22:23
@Auth ： 叶东宇
@File ：strStr.py
"""
def strStr(haystack, needle):
    haystack_left = 0
    haystack_right = 0
    needle_left = 0
    needle_right = 0
    while haystack_left <= len(haystack) - len(needle):
        if haystack[haystack_left] == needle[needle_left]:
            while needle_right < len(needle):
                if haystack[haystack_right] == needle[needle_right]:
                    needle_right += 1
                    haystack_right += 1
                else:
                    break
            if needle_right < len(needle):
                haystack_left += 1
                needle_right = 0
                haystack_right = haystack_left
                continue
            else:
                return haystack_left
        else:
            haystack_left += 1
            needle_right = 0
            haystack_right = haystack_left
    if haystack_left >= len(haystack) - len(needle):
        return -1

if __name__ == "__main__":
    haystack = "llo"
    needle = "llo"
    print(strStr(haystack, needle))
